# Maintainer: Sébastien Luttringer
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Dale Blount <dale@archlinux.org>

pkgname=iperf
pkgver=2.1.9
pkgrel=1
pkgdesc='A tool to measure maximum TCP bandwidth'
arch=('loong64' 'x86_64')
license=('custom')
url='https://sourceforge.net/projects/iperf2/'
depends=('glibc' 'gcc-libs')
install=iperf.install
source=("https://downloads.sourceforge.net/iperf2/iperf-$pkgver.tar.gz"
        'iperf-tcp.service'
        'iperf-udp.service')
sha256sums=('5c0771aab00ef14520013aef01675977816e23bb8f5d9fde016f90eb2f1be788'
            '5bfeaf4b7fc9bcc424cfc2257c6eefd21ed491bd140e9ae5562b270dcf84d794'
            'fec34a6f352619caaf4ed3bc23f75a3ffb6b3ab5c2947cd2c24c6be36851738c')
prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done
  :
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr \
              --enable-ipv6 \
              --enable-multicast \
              --enable-threads \
              --enable-fastsampling
  make
}

package() {
  pushd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/iperf/LICENSE"
  popd
  # systemd
  install -Dm644 iperf-tcp.service "$pkgdir/usr/lib/systemd/system/iperf-tcp.service"
  install -Dm644 iperf-udp.service "$pkgdir/usr/lib/systemd/system/iperf-udp.service"
}

# vim:set ts=2 sw=2 et:
